var feedTargetElement = "";
var feedURLMapping = {}

var toolTipOptions = { offset: [10, 30] }

function processFeed(result){
		feedTargetElement = feedURLMapping[result.feed.feedUrl]		
		var feedContainer = jq("#"+feedTargetElement);
		if(!result.error){
			feedContainer.empty();
			for(var i = 0; i < result.feed.entries.length; i++){
				var entry = result.feed.entries[i];
				var fItem = document.createElement("dd");
				var fLink = document.createElement("a");
				var datePublished = new Date(entry.publishedDate);
				var span_desc = document.createElement("span");
				span_desc.innerText = datePublished.toUTCString();
				jq(span_desc).addClass("apknFeedItemDate");
				jq(fItem).addClass("portletItem");
				jq(fLink).attr("href", entry.link);
				jq(fLink).attr("title", entry.contentSnippet);
				jq(fLink).attr("target", "_blank");
				jq(fLink).text(entry.title.substring(0,30)+'...');
				jq(fLink).addClass("apkn_feed_item");
				jq(fItem).append(fLink);
				jq(fItem).append(span_desc);
				feedContainer.append(fItem);
			}
		}else{
			errorNode = document.createElement("span").innerText = "Could not load text";
			feedContainer.append(errorNode);
		}
		
		jq("a.apkn_feed_item[title]").tooltip(toolTipOptions);
}

google.load("feeds", "1");
function apknFeedLoader(){
	jq("dd.portletItem[rel]", "#portal-column-two").each(
		function(fidx, felement){
			feed_url = jq(felement).attr("rel");
			dom_id = jq(felement).attr("id");
			feedURLMapping[feed_url] = dom_id;
			var feed = new google.feeds.Feed(feed_url);
			feed.setNumEntries(5);
			feed.load(processFeed)
		}
	);
}
google.setOnLoadCallback(apknFeedLoader);
